﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace bts_webapp
{
    public partial class ObjectInfo : BasePage
    {
        public string Type {
            get
            {
                return Request.Params["type"].Trim();
            }
        }

        public string Id {
            get
            {
                return Request.Params["id"].Trim();
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            var id = this.Id.Trim();
            var type = this.Type.Trim();
            this.pnStation.Visible = type == "st";
            this.pnFlow.Visible = type == "fl";
            this.pnDevice.Visible = type == "dv";
            switch (type)
            { 
                case "st":  //station
                    var station = this.DbContext.VIBA_TRAMs.FirstOrDefault(t => t.Tram_Id == id);
                    if (station != null) {
                        this.litStationId.Text = station.Tram_Id;
                        this.litStationName.Text = station.Tram_Ten;
                        this.litStationAddress.Text = station.Tram_DiaChi;
                        this.litStationNote.Text = station.GhiChu;
                        this.litStationResPerson.Text = station.NguoiPhuTrach;
                        this.litStationStatus.Text = station.Status == 1 ? "Active" : "Inactive";
                    }
                    break;

                case "dv":
                   
                    var device = this.DbContext.VIBA_THIET_BIs.FirstOrDefault(t => t.ThietBi_Id == id);
                    if (device != null)
                    {
                        this.litDeviceId.Text = device.ThietBi_Id;
                        this.litDeviceName.Text = device.ThietBi_Ten;
                        this.litDeviceLabel.Text = device.ThietBi_NhanHieu;
                        //this.litDevicePortCount.Text = device.ThietBi_SoPort.ToString();
                        //this.litdeviceCardName.Text = device.ThietBi_TenCard;
                        this.litDeviceStatus.Text = device.Status ==1? "Active": "Inactive";
                        this.litDeviceNote.Text = device.ThietBi_GhiChu;
                    }

                    break;

                case "fl":
                  
                    var flow = this.DbContext.VIBA_LUONGs.FirstOrDefault(t => t.Luong_Id == id);
                    if (flow != null)
                    {
                        this.litFlowId.Text = flow.Luong_Id;
                        this.litFlowName.Text = flow.Luong_Ten;
                        this.litFlowNote.Text = flow.Luong_GhiChu;
                        this.litFlowOutgoingPort.Text = flow.Luong_Port_Di.ToString();
                        this.litFlowIncomingPort.Text = flow.Luong_Port_Den.ToString();
                        this.litFlowInCommingStation.Text = flow.Luong_Id_Tram_Den;
                        this.litFlowOutgoingStation.Text = flow.Luong_Id_Tram_Di;
                        this.litFlowHistory.Text = flow.Luong_Lich_Su_Duong_Di;
                        this.litFlowStatus.Text = flow.Status == 1 ? "Active" : "Inactive";

                    }

                    break;
            }
        }
    }
}